home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3527 < prev    next >
Encoding:
Text File  |  1996-08-06  |  5.3 KB  |  187 lines

  1. Path: digex.net!not-for-mail
  2. From: dave@access2.digex.net (Dave Eidman)
  3. Newsgroups: comp.lang.c++
  4. Subject: Problem with C++ name mangling of Windows C exported functions
  5. Date: 24 Jan 1996 12:07:04 -0500
  6. Organization: Express Access, Greenbelt, Maryland USA
  7. Message-ID: <4e5ovo$1ap@access2.digex.net>
  8. NNTP-Posting-Host: access2.digex.net
  9.  
  10. If anyone can shed some light on the following problem, I would appreciated it.
  11.  
  12. In Borland C++ 4.5, 
  13.    
  14.    I am able to compile and execute the following example that comes from 
  15.    Chap. 19 in the Petzold book "Programing Windows 3.1" using the 
  16.    DOS command line,
  17.  
  18.    bcc -c -ms! -w-par -P -W -2 strlib.c
  19.  
  20.    But utilizing the IDE, I encounter the indicated errors when the code
  21.    attempts to turn off name mangling for exported functions.
  22.  
  23. CONTENTS OF ERROR WINDOW IS AS FOLLOWS:
  24. -----------------------------------------------------------------------------------------------
  25. Compiling STRLIB.C:
  26. Error STRLIB.H 7: Declaration terminated incorrectly
  27. Error STRLIB.C 9: Declaration terminated incorrectly
  28. Warning STRLIB.C 23: Parameter 'hInstance' is never used in function LibMain
  29. Warning STRLIB.C 23: Parameter 'wDataSeg' is never used in function LibMain
  30. Warning STRLIB.C 23: Parameter 'lpszCmdLine' is never used in function LibMain
  31. Warning STRLIB.C 28: Parameter 'nParam' is never used in function WEP
  32. Error STRLIB.C 52: Undefined symbol 'hStrings' in function AddString
  33. Error STRLIB.C 81: Undefined symbol 'hStrings' in function DeleteString
  34. Error STRLIB.C 107: Undefined symbol 'hStrings' in function GetStrings
  35.  
  36. -----------------------------------------------------------------------------------------------
  37.    
  38.    
  39.    The following is source code from the Petzold Book
  40.  
  41.    strlib.c:
  42. -----------------------------------------------------------------------------------------------
  43. /*------------------------------------------------
  44.    STRLIB.C -- Library module for STRPROG program
  45.                (c) Charles Petzold,  1992
  46.   ------------------------------------------------*/
  47.  
  48. #include <windows.h>
  49. #include "strlib.h"
  50.  
  51. extern "C" {
  52. int FAR PASCAL _export WEP (int) ;
  53. }
  54.  
  55. HANDLE hStrings [256] ;
  56. short  nTotal = 0 ;
  57.  
  58. int FAR PASCAL LibMain (HANDLE hInstance, WORD wDataSeg, WORD wHeapSize,
  59.                         LPSTR lpszCmdLine)
  60.      {
  61.      if (wHeapSize > 0)
  62.           UnlockData (0) ;
  63.  
  64.      return 1 ;
  65.      }
  66.  
  67. int FAR PASCAL _export WEP (int nParam)
  68.      {
  69.      return 1 ;
  70.      }
  71.  
  72. BOOL FAR PASCAL _export AddString (LPSTR lpStringIn)
  73.      {
  74.      HANDLE hString ;
  75.      NPSTR  npString ;
  76.      short  i, nLength, nCompare ;
  77.  
  78.      if (nTotal == 255)
  79.           return FALSE ;
  80.  
  81.      if (0 == (nLength = lstrlen (lpStringIn)))
  82.           return FALSE ;
  83.  
  84.      if (NULL == (hString = LocalAlloc (LHND, 1 + nLength)))
  85.           return FALSE ;
  86.  
  87.      npString = LocalLock (hString) ;
  88.      lstrcpy (npString, lpStringIn) ;
  89.      AnsiUpper (npString) ;
  90.      LocalUnlock (hString) ;
  91.  
  92.      for (i = nTotal ; i > 0 ; i--)
  93.           {
  94.           npString = LocalLock (hStrings [i - 1]) ;
  95.           nCompare = lstrcmpi (lpStringIn, npString) ;
  96.           LocalUnlock (hStrings [i - 1]) ;
  97.  
  98.           if (nCompare > 0)
  99.                {
  100.                hStrings [i] = hString ;
  101.                break ;
  102.                }
  103.           hStrings [i] = hStrings [i - 1] ;
  104.           }
  105.  
  106.      if (i == 0)
  107.           hStrings [0] = hString ;
  108.  
  109.      nTotal++ ;
  110.      return TRUE ;
  111.      }
  112.  
  113. BOOL FAR PASCAL _export DeleteString (LPSTR lpStringIn)
  114.      {
  115.      NPSTR npString ;
  116.      short i, j, nCompare ;
  117.  
  118.      if (0 == lstrlen (lpStringIn))
  119.           return FALSE ;
  120.  
  121.      for (i = 0 ; i < nTotal ; i++)
  122.           {
  123.           npString = LocalLock (hStrings [i]) ;
  124.           nCompare = lstrcmpi (npString, lpStringIn) ;
  125.           LocalUnlock (hStrings [i]) ;
  126.  
  127.           if (nCompare == 0)
  128.                break ;
  129.           }
  130.  
  131.      if (i == nTotal)
  132.           return FALSE ;
  133.  
  134.      for (j = i ; j < nTotal ; j++)
  135.           hStrings [j] = hStrings [j + 1] ;
  136.  
  137.      nTotal-- ;
  138.      return TRUE ;
  139.      }
  140.  
  141. short FAR PASCAL _export GetStrings (FPSTRCB lpfnGetStrCallBack, LPVOID lpParam)
  142.      {
  143.      BOOL  bReturn ;
  144.      NPSTR npString ;
  145.      short i ;
  146.  
  147.      for (i = 0 ; i < nTotal ; i++)
  148.           {
  149.           npString = LocalLock (hStrings [i]) ;
  150.           bReturn = lpfnGetStrCallBack (npString, lpParam) ;
  151.           LocalUnlock (hStrings [i]) ;
  152.  
  153.           if (bReturn == FALSE)
  154.                return i + 1 ;
  155.           }
  156.      return nTotal ;
  157.      }
  158.    
  159. -----------------------------------------------------------------------------------------------   
  160.    
  161.    strlib.h
  162.    
  163. -----------------------------------------------------------------------------------------------
  164. /*----------------------
  165.    STRLIB.H header file
  166.   ----------------------*/
  167.  
  168. typedef BOOL (FAR PASCAL _export * FPSTRCB) (LPSTR, LPVOID) ;
  169.  
  170. extern "C" {
  171. BOOL  FAR PASCAL _export AddString    (LPSTR) ;
  172. BOOL  FAR PASCAL _export DeleteString (LPSTR) ;
  173. short FAR PASCAL _export GetStrings   (FPSTRCB, LPVOID) ;
  174. }
  175.  
  176. -----------------------------------------------------------------------------------------------
  177.    
  178.    The windows.h file is the Version 3.10 that is included with BC4.5 
  179.    in the file "\bc45\include\windows.h"
  180.  
  181.  
  182.  
  183.    Thanks for any explanations that you can provide 
  184.  
  185.    dave@access.digex.net
  186.  
  187.